#include <iostream>
#include <string>
#include <cmath>

using namespace std;
class Solution {
public:
    int NumberOf1Between1AndN_Solution(int n)
    {
    	if(n <= 0)
    		return 0;
  		string s(to_string(n));
  		return count1(s);
    }

    int count1(string &s)
    {
    	string s1(s,1,s.size());
    	if(s.size() > 1 && s[0] == '0')
    		return count1(s1);
    	if(s.size() == 1)
    		if(s[0] >= '1')
    			return 1;
    		else
    			return 0;
    	int sum = 0;
    	if(s[0] == '1')
    		sum = stoi(&s[1]) + 1 + pow(10,s.size()-2) * (s.size() - 1);
    	else
    		sum = pow(10,s.size()-1) + pow(10,s.size()-2) * (s[0] - '0') * (s.size() - 1);
    	return count1(s1) + sum;
    }
};

int main()
{
	Solution s;
	int  n = 21345;
	cout<<s.NumberOf1Between1AndN_Solution(n)<<endl;
	return 0;
}